package com.ranjith.struts2.actions;

import java.util.List;

import com.ranjith.struts2.beans.User;

public class OgnlElAndTcAction {
	/*public OgnlElAndTcAction() {
		super();
		for (User user : users) {
			System.out.println("Constructor");
			System.out.println(user);
		}
	}*/

	private int num;
	private int[] numArray;

	private String name;
	private String[] names; // if using indexes to refer a string array in jsp's
							// it should be initialized in java

	private User user;
	private User[] users = { new User(), new User(), new User() };
	// Object Arrays Should be initialized and should be indexed from jsp for populating
	

	private List nameList;
	private List<String> nameListWithGenerics;

	private List<User> usersList;// use indexes to populate in jsp's

	
	public int getNum() {
		return num;
	}

	public void setNum(int num) {
		this.num = num;
	}

	public int[] getNumArray() {
		return numArray;
	}

	public void setNumArray(int[] numArray) {
		this.numArray = numArray;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String[] getNames() {
		return names;
	}

	public void setNames(String[] names) {
		this.names = names;
	}

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	public User[] getUsers() {
		return users;
	}

	public void setUsers(User[] users) {
		this.users = users;
	}

	public List getNameList() {
		return nameList;
	}

	public void setNameList(List nameList) {
		this.nameList = nameList;
	}

	public List<String> getNameListWithGenerics() {
		return nameListWithGenerics;
	}

	public void setNameListWithGenerics(List<String> nameListWithGenerics) {
		this.nameListWithGenerics = nameListWithGenerics;
	}

	public List<User> getUsersList() {
		return usersList;
	}

	public void setUsersList(List<User> usersList) {
		this.usersList = usersList;
	}

	

	public String execute() {
		//processPrimitive();
		//processObjectAndObjectArray();		
		//processListOfString();
		processLists();

		return "success";
	}

	private void processListOfString() {
		System.out.println("********************");
		System.out.println("Non generic list");
		for (Object obj : nameList) {
			System.out.println(obj);
		}
		System.out.println("generic list");
		for (String str : nameListWithGenerics) {
			System.out.println(str);
		}
		System.out.println("********************");
	}

	/*private void processListOfArrays() {
		System.out.println("********************");
		for (User[] userArray : userArrayList) {
			for (User user : userArray) {
				System.out.println(user.getUsername());
			}
		}
		System.out.println("********************");
	}*/

	private void processPrimitive() {
		System.out.println("*****************************");
		System.out.println("normal int--------" + num);
		System.out.println("int array---------");
		for (int i : numArray) {
			System.out.println(i);
		}
		System.out.println("normal String--------" + name);
		System.out.println("String array---------");
		for (String i : names) {
			System.out.println(i);
		}

		

		System.out.println("*****************************");

	}

	private void processObjectAndObjectArray() {
		System.out.println("**********************************");
		
		System.out.println("User object--------" + user.getUsername());
		System.out.println("User Array---------");
		for (User user : users) {
			System.out.println(user.getUsername());
		}
		
		/*
*/
		System.out.println("**********************************");
	}
	private void processLists(){
		System.out.println("**********************************");
		System.out.println("List<User>");
		for (User user : usersList) {
			System.out.println(user.getUsername());
		}
		System.out.println("**********************************");
	}

}
